package softtech.apps.sync.android.util;

import java.util.Comparator;

import softtech.apps.model.RowRecord;

public class RowRecordComparator implements Comparator<RowRecord>{

	private boolean isAscending;
	
	public static RowRecordComparator getNameAsc(boolean ascending) {
		return new RowRecordComparator(ascending);
	}
	
	private RowRecordComparator(boolean ascending){
		isAscending = ascending;
	}
	
	@Override
	public int compare(RowRecord lhs, RowRecord rhs) {
		// TODO Auto-generated method stub
		
		String lName = lhs.getmFileName().split("-")[0];
		String rName = rhs.getmFileName().split("-")[0];
		int res = String.CASE_INSENSITIVE_ORDER.compare(lName, rName);
		if (res == 0) {
			res = lName.compareTo(rName);
		}
		return isAscending ? res : -res;
	}

}
